﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.ModularFixture.CUiMFLoadConfigurationDlg
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using EMPMODELLib;
using EMPTYPELIBRARYLib;
using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using Tecnomatix.Engineering;
using Tecnomatix.Engineering.Ui;
using Tecnomatix.Planning;


namespace DnProcessSimulateCommands.ModularFixture;

public class CUiMFLoadConfigurationDlg : TxForm
{
  private TxObjEditBoxCtrl m_configuration;
  private Label label2;
  private Button m_ok;
  private Button m_cancel;
  private CApMFAdministratorManager m_adminManager;
  private IContainer components;

  public CUiMFLoadConfigurationDlg(CApMFAdministratorManager manager)
  {
    this.m_adminManager = manager;
    this.InitializeComponent();
  }

  private void CUiMFLoadConfigurationDlg_Load(object sender, EventArgs e)
  {
    this.m_configuration.SetPickProviders(new TxPickProvider[2]
    {
      (TxPickProvider) 4,
      (TxPickProvider) 6
    });
    this.m_configuration.ListenToPick = true;
    this.m_configuration.Focus();
    this.m_configuration.SetValidator((ITxValidator) new CApMFConfigurationValidator());
    this.m_ok.Enabled = false;
  }

  private void m_ok_Click(object sender, EventArgs e)
  {
    Cursor current = Cursor.Current;
    Cursor.Current = Cursors.WaitCursor;
    ((Form) this).Close();
    if (!this.m_adminManager.LoadConfiguration(this.m_configuration.Object as TxPlanningObject, 1))
    {
      int num = (int) TxMessageBox.Show(CApMFAdminUtils.m_resourceManager.GetString("ERROR_IN_LOAD_CONFIGURERROR_IN_LOAD_CONFIGURATION"), CApMFAdminUtils.m_resourceManager.GetString("CMD_CONFIGURATION_ADMINISTRATOR_NAME"), MessageBoxButtons.OK, MessageBoxIcon.Hand);
    }
    Cursor.Current = current;
  }

  private void m_cancel_Click(object sender, EventArgs e) => ((Form) this).Close();

  private void m_configuration_Picked(object sender, TxObjEditBoxCtrl_PickedEventArgs args)
  {
    TxPlanningObject planningObj = args.Object as TxPlanningObject;
    if (!planningObj.IsDerivedFromPlanningType("UnitConfigurationPrototype") || !this.IsConfigurationType(planningObj))
    {
      ((Control) this.m_configuration).Text = "";
      this.m_configuration.Object = (ITxObject) null;
      this.m_ok.Enabled = false;
    }
    else
      this.m_ok.Enabled = true;
  }

  private bool IsConfigurationType(TxPlanningObject planningObj)
  {
    bool flag = false;
    EmpContext empContext;
    empContext.sessionId = TxApplication.ActiveDocument.eMSSessionId;
    TxEmsServicesProvider servicesProvider = planningObj.PlatformServicesProvider as TxEmsServicesProvider;
    EmpFieldInfo field = ((IEmpObject) new EmpObjectClass()).GetField(ref empContext, ref new EmpObjectKey()
    {
      objectId = servicesProvider.InternalId
    }, "ConfigurationType");
    if (field.Value != null)
    {
      string str = (string) field.Value;
      if (str.Equals("Configuration") || str.Equals("FixtureBase") || str.Equals("Unit"))
        flag = true;
    }
    return flag;
  }

  private void m_configuration_TypeInvalid(object sender, EventArgs e) => this.m_ok.Enabled = false;

  protected virtual void Dispose(bool disposing)
  {
    if (disposing && this.components != null)
      this.components.Dispose();
    base.Dispose(disposing);
  }

  private void InitializeComponent()
  {
    ComponentResourceManager componentResourceManager = new ComponentResourceManager(typeof (CUiMFLoadConfigurationDlg));
    this.m_configuration = new TxObjEditBoxCtrl();
    this.label2 = new Label();
    this.m_ok = new Button();
    this.m_cancel = new Button();
    ((Control) this).SuspendLayout();
    this.m_configuration.ListenToPick = false;
    ((Control) this.m_configuration).Location = new Point(15, 37);
    ((Control) this.m_configuration).Name = "m_configuration";
    this.m_configuration.Object = (ITxObject) null;
    this.m_configuration.PickLevel = (TxPickLevel) 1;
    this.m_configuration.ReadOnly = false;
    ((Control) this.m_configuration).Size = new Size(236, 20);
    ((Control) this.m_configuration).TabIndex = 0;
    this.m_configuration.ValidatorType = (TxValidatorType) 1;
    this.m_configuration.TypeInvalid += new EventHandler(this.m_configuration_TypeInvalid);
    this.m_configuration.Picked += new TxObjEditBoxCtrl_PickedEventHandler(this.m_configuration_Picked);
    this.label2.AutoSize = true;
    this.label2.Location = new Point(12, 12);
    this.label2.Name = "label2";
    this.label2.Size = new Size(103, 13);
    this.label2.TabIndex = 1;
    this.label2.Text = "Configuration Name:";
    this.m_ok.DialogResult = DialogResult.OK;
    this.m_ok.Location = new Point(95, 72);
    this.m_ok.Name = "m_ok";
    this.m_ok.Size = new Size(75, 23);
    this.m_ok.TabIndex = 2;
    this.m_ok.Text = "OK";
    this.m_ok.UseMnemonic = false;
    this.m_ok.UseVisualStyleBackColor = true;
    this.m_ok.Click += new EventHandler(this.m_ok_Click);
    this.m_cancel.DialogResult = DialogResult.Cancel;
    this.m_cancel.Location = new Point(176 /*0xB0*/, 72);
    this.m_cancel.Name = "m_cancel";
    this.m_cancel.Size = new Size(75, 23);
    this.m_cancel.TabIndex = 3;
    this.m_cancel.Text = "Cancel";
    this.m_cancel.UseVisualStyleBackColor = true;
    this.m_cancel.Click += new EventHandler(this.m_cancel_Click);
    ((Form) this).AcceptButton = (IButtonControl) this.m_ok;
    ((ContainerControl) this).AutoScaleDimensions = new SizeF(6f, 13f);
    ((ContainerControl) this).AutoScaleMode = AutoScaleMode.Font;
    ((Form) this).CancelButton = (IButtonControl) this.m_cancel;
    ((Form) this).ClientSize = new Size(261, 107);
    ((Control) this).Controls.Add((Control) this.m_cancel);
    ((Control) this).Controls.Add((Control) this.m_ok);
    ((Control) this).Controls.Add((Control) this.label2);
    ((Control) this).Controls.Add((Control) this.m_configuration);
    ((Form) this).FormBorderStyle = FormBorderStyle.FixedDialog;
    ((Form) this).Icon = (Icon) componentResourceManager.GetObject("$this.Icon");
    ((Form) this).MaximizeBox = false;
    ((Form) this).MinimizeBox = false;
    ((Control) this).Name = nameof (CUiMFLoadConfigurationDlg);
    ((Form) this).ShowIcon = false;
    ((Control) this).Text = "Load Configuration";
    ((Form) this).TopMost = true;
    ((Form) this).Load += new EventHandler(this.CUiMFLoadConfigurationDlg_Load);
    ((Control) this).ResumeLayout(false);
    ((Control) this).PerformLayout();
  }
}
